package com.dbserver;

import java.sql.*;

public class Condb {
	 String driver="com.mysql.jdbc.Driver";
	 String url="jdbc:mysql://123.56.40.112:3306/creditmanage";
     String user="root";
     String passwd="123456";
	 Connection conn=null;
	 ResultSet rs=null;
	 Statement st=null;
	 public Condb(){
	  try {
	   Class.forName(driver);
	  }catch(ClassNotFoundException e){
	   e.printStackTrace();
	  }
	 }
	 //in order to update and insert operation
	 public int update(String sql){
	  int result=0;
	  try{
	   conn=DriverManager.getConnection(url,user,passwd);
	   st=conn.createStatement();
	   result=st.executeUpdate(sql);
	  }catch (SQLException e){
	   e.printStackTrace();
	  }
	  return result;
	 }
	 //in order to select operation
	 public ResultSet query(String sql){
	  try{
	   conn=DriverManager.getConnection(url,user,passwd);
	   st=conn.createStatement();
	   rs=st.executeQuery(sql);
	  }catch (SQLException e){
	   e.printStackTrace();
	  }
	  return rs;
	 }
	 //in order to delete operation
	 public int del(String sql){
	  int DelResult=0;
	  try{
	   conn=DriverManager.getConnection(url,user,passwd);
	   st=conn.createStatement();
	   DelResult=st.executeUpdate(sql);
	  }catch (SQLException e){
	   e.printStackTrace();
	  }
	  return DelResult;
	 }
	 //in order to close with database
	 public void close(){
	  try{
	   if (rs!=null)
	    rs.close();
	  }catch(Exception e){
	   e.printStackTrace();
	  }
	  try{
	   if (conn!=null)
	    conn.close();
	  }catch(Exception e){
	   e.printStackTrace();
	  }
	 }
	}

		
